package com.zainaer.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.TabHost;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.zainaer.R;

public class ZainaerActivity extends TabActivity implements OnCheckedChangeListener {
	
	private TabHost tabhost;
	
    private Intent mMapIntent;  
    private Intent mContactIntent;  
    private Intent mChatIntent;  
    private Intent mMoreIntent;  
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.tab);
        
        this.mMapIntent = new Intent(this, MapViewActivity.class); 
        this.mContactIntent = new Intent(this, ContactActivity.class); 
        this.mChatIntent = new Intent(this, ChatListActivity.class); 
        this.mMoreIntent = new Intent(this, TestActivity3.class); 
        
        initRadios();  
        setupIntent();  

    }
    
    private void setupIntent() {  
        this.tabhost = getTabHost();  
  
        tabhost.addTab(buildTabSpec("map_tab", R.string.tab1,  
                R.drawable.btn_position_blue, mMapIntent));  
  
        tabhost.addTab(buildTabSpec("contact_tab", R.string.tab2,  
                R.drawable.btn_contact_blue, mContactIntent));  
  
        tabhost.addTab(buildTabSpec("chatlist_tab", R.string.tab3,  
                R.drawable.btn_chat_blue, mChatIntent));  
  
  
        tabhost.addTab(buildTabSpec("more_tab", R.string.tab4,  
                R.drawable.btn_more_blue, mMoreIntent));
        tabhost.setCurrentTab(0);
  
    }  

    private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,  
            final Intent content) {  
        return this.tabhost  
                .newTabSpec(tag)  
                .setIndicator(getString(resLabel),  
                        getResources().getDrawable(resIcon))  
                .setContent(content);  
    }  

    private void initRadios() {  
        ((RadioButton) findViewById(R.id.menu_position)).setOnCheckedChangeListener(this);  
        ((RadioButton) findViewById(R.id.menu_contact)).setOnCheckedChangeListener(this);  
        ((RadioButton) findViewById(R.id.menu_chat)).setOnCheckedChangeListener(this);  
        ((RadioButton) findViewById(R.id.menu_more)).setOnCheckedChangeListener(this);  
   }  

	@Override
	 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {  
        if (isChecked) {  
            switch (buttonView.getId()) {  
            case R.id.menu_position:  
                this.tabhost.setCurrentTabByTag("map_tab");  
                break;
            case R.id.menu_contact:  
                this.tabhost.setCurrentTabByTag("contact_tab");  
                break;
            case R.id.menu_chat:  
                this.tabhost.setCurrentTabByTag("chatlist_tab");  
                break;
            case R.id.menu_more:  
                this.tabhost.setCurrentTabByTag("more_tab");  
                break;
            }  
        }  
    }  

}